let fs = require('fs-extra');
let mysql =require('mysql2/promise');
//执行数据效验及信息初始化

exports.systemInstll = async function (params) {
    try{
//向json 文件写入数据
let pathName =__dirname +'/../config/config.json';
 await fs.writeJson(pathName,params);
//测试数据库是否联通
let connection = await mysql.createConnection({host:params.sqlAddress,user:params.sqlUser,password:params.sqlPwd});
connection.end();
}
   catch(err){
    
      if(err.code==="ENOTFOUND" || err.code==="ER_ACCESS_DENIED_ERROR" ){
            return err.code;
      }
   }
}

//向config.json 中写入数据
exports.writeJsons =  async  function(params){
    try{
        //向json 文件写入数据
        let pathName =__dirname +'/../config/config.json';
         await fs.writeJson(pathName,params);
         return true
        }
           catch(err){
            return false
           }
        
}
